cc.Class({
    extends: cc.Component,

    properties: {
        id: 0,
        spf:cc.SpriteFrame,
    },
    
    init(data) {
        this.id = data.id
        const sp = this.node.getComponent(cc.Sprite)
        sp.spriteFrame = data.iconSF
        // todo 控制一下每种水果的尺寸

        //拖尾宽度重新计算
        var ms = this.node.getChildByName("tuowei").getComponent(cc.MotionStreak);
        ms.stroke = this.node.width*2/3;
    },
    start() {

    },

    resetSprite(){
        const sp = this.node.getComponent(cc.Sprite)
        sp.spriteFrame = this.spf
    },

    onBeginContact(contact, self, other) {
        // 貌似检测有点消耗性能
        if (self.node && other.node) {
            const s = self.node.getComponent('Fruit')
            const o = other.node.getComponent('Fruit')
            if (s && o){
                if(self.node.getChildByName("wanneng").active==true){
                    self.node.emit('sameContact', {self, other});
                }else{
                    if(s.id === o.id){
                        self.node.emit('sameContact', {self, other});
                    }
                }
            }
        }
    },
});
